package com.she.iiicoursecenter.view.tab1;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

import com.she.iiicoursecenter.R;
import com.she.iiicoursecenter.activity.tab1_infomation.Tab1_CourseSet;
import com.she.iiicoursecenter.activity.tab1_infomation.Tab1_CourseSingle;
import com.she.iiicoursecenter.activity.tab1_infomation.Tab1_MainActivity;
import com.she.iiicoursecenter.adapter.Tab1_CourseSetAdapter;
import com.she.iiicoursecenter.adapter.Tab1_MainAdapter;
import com.she.iiicoursecenter.bean.CourseSetBundleBean;
import com.she.iiicoursecenter.bean.CourseSingleBundleBean;
import com.she.iiicoursecenter.bean.ViewChageDataBean;
import com.she.iiicoursecenter.event.connect.bean.GetContentListBean;
import com.she.iiicoursecenter.event.connect.bean.GetItemListBean;
import com.she.iiicoursecenter.view.template.CustomizedView;

public class Tab1_CourseSetView extends CustomizedView implements OnClickListener {
	//
	//

	// test only!!!
	private ImageView mImgBack;

	// test only!!!!!
//	private Button mbtnGo;

	private ListView mListView;
	private Tab1_CourseSetAdapter tab1_CourseSetAdapter;
	private List<GetContentListBean> date;

	public Tab1_CourseSetView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		init();
	}

	private void init() {
		//
		LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.tab1_courseset, this, true);
		//

		// test only!!!
		mImgBack = (ImageView) this.findViewById(R.id.img_back);
		mImgBack.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				getApp().fadeout = true;
				getApp().getContentListBeanData().clear();
				Message msg = Tab1_CourseSetView.this.getApp().mChangeViewHandler.obtainMessage();
				msg.what = Tab1_CourseSetView.this.getApp().MSG_WHAT_CHANGEVIEW;
				ViewChageDataBean dataBean = new ViewChageDataBean(Tab1_CourseSet.class, Tab1_MainActivity.class, null);
				msg.obj = dataBean;
				Tab1_CourseSetView.this.getApp().mChangeViewHandler.sendMessage(msg);

			}
		});

		// test only!!!!
//		mbtnGo = (Button) this.findViewById(R.id.btn_goto);
//		mbtnGo.setOnClickListener(new OnClickListener() {
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				Message msg = Tab1_CourseSetView.this.getApp().mChangeViewHandler.obtainMessage();
//				msg.what = Tab1_CourseSetView.this.getApp().MSG_WHAT_CHANGEVIEW;
//				CourseSingleBundleBean bundleBean = new CourseSingleBundleBean("test1", "test2", "test3");
//				ViewChageDataBean dataBean = new ViewChageDataBean(Tab1_CourseSet.class, Tab1_CourseSingle.class, bundleBean);
//				msg.obj = dataBean;
//				Tab1_CourseSetView.this.getApp().mChangeViewHandler.sendMessage(msg);
//			}
//		});
		
		date = this.getApp().getContentListBeanData();
		
		tab1_CourseSetAdapter = new Tab1_CourseSetAdapter(getContext(), date);
		mListView = (ListView) this.findViewById(R.id.tv_listview);
		mListView.setAdapter(tab1_CourseSetAdapter);
		mListView.setDivider(new ColorDrawable(Color.TRANSPARENT));// 去除listview分隔線
		mListView.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				// TODO Auto-generated method stub
				getApp().fadein = true;
				Message msg = Tab1_CourseSetView.this.getApp().mChangeViewHandler.obtainMessage();
				msg.what = Tab1_CourseSetView.this.getApp().MSG_WHAT_CHANGEVIEW;
				CourseSingleBundleBean bundleBean = new CourseSingleBundleBean( date.get(arg2).getContentId(), date.get(arg2).getContentName());
				ViewChageDataBean dataBean = new ViewChageDataBean(Tab1_CourseSet.class, Tab1_CourseSingle.class, bundleBean);
				msg.obj = dataBean;
				Tab1_CourseSetView.this.getApp().mChangeViewHandler.sendMessage(msg);
				Tab1_CourseSetView.this.getApp().tab2InCourseSingle = false;
				Tab1_CourseSetView.this.getApp().tab3InCourseSingle = false;
			}
		});

	}

	public void onClick(View v) {
		// TODO Auto-generated method stub

	}
	
	public void notifyAdapter(){
		tab1_CourseSetAdapter.notifyDataSetChanged();
	}
	
}
